import { _decorator, Component, Node, Label } from 'cc';
import { Hero } from '../Hero';
const { ccclass, property } = _decorator;

@ccclass('HeroState')
export class HeroState extends Component {

    @property({ type: Hero })
    hero: Hero = null

    @property(Label)
    state: Label = null

    @property(Label)
    level: Label = null

    @property(Label)
    life: Label = null

    @property(Label)
    atk: Label = null

    @property(Label)
    defense: Label = null

    @property(Label)
    magicDefense: Label = null

    @property(Label)
    money: Label = null

    @property(Label)
    exper: Label = null

    @property(Label)
    yellowKeys: Label = null

    @property(Label)
    blueKeys: Label = null

    @property(Label)
    redKeys: Label = null

    @property(Label)
    greenKeys: Label = null

    start() {

    }

    update(deltaTime: number) {
        if (this.hero) {
            this.refreshState(this.hero._heroState)
        }
    }

    refreshState(state: any) {
        this.state.string = state.state.state
        this.level.string = state.state.level
        this.life.string = state.fight.life
        this.money.string = state.state.money
        this.exper.string = state.state.exper
        this.atk.string = state.fight.atk
        this.defense.string = state.fight.defense
        this.magicDefense.string = state.fight.magicDefense

        //keys
        this.yellowKeys.string = state.keys.yellow
        this.blueKeys.string = state.keys.blue
        this.redKeys.string = state.keys.red
        this.greenKeys.string = state.keys.green
    }
}

